package com.feng.main;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainTest {
	
	public static void main(String[] args) {
		
//		DownLoadImg down = new DownLoadImg();
//		String startUrl = "http://www.sslingyu.com/mz_pbl/jdly_json.php?st=0&en=10&type=2&mode=1&mode_lv=2";
//		String startUrl = "http://baobab.wandoujia.com/api/v2/videos"
//				+ "?start=10"
//				+ "&num=10"
//				+ "&categoryName=%E5%88%9B%E6%84%8F"
//				+ "&strategy=date"
//				+ "&udid=b1dfb124163b41f9a7c6af1e6cd468d2dcb60b0d"
//				+ "&vc=58"
//				+ "&vn=1.7.1&deviceModel=HUAWEI_H30_T00%26T10"
//				+ "&first_channel=eyepetizer_PP_market"
//				+ "&last_channel=eyepetizer_PP_market";
		
		String startUrl = "http://www.nationalgeographic.com.cn/photography/";
		
		Pattern p = Pattern.compile("http://([\\w-]+\\.)+[\\w-]+");
		
		Matcher m = p.matcher(startUrl);
		
//		down.start(startUrl);
		m.find();
		String regex = m.group();
		
		System.out.println("regex : "+regex);
		
		Queues.htmlUrlQueue.offer(startUrl);
		
		//在线程池开启三个线程
		ExecutorService pool = Executors.newFixedThreadPool(3);
		
		Thread add = new AddQueue(regex);
		Thread down = new DownloadImages();
		
		//加入线程池
		pool.execute(add);
		
		try {
			//延时进行下载
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		pool.execute(down);
		pool.execute(down);
		
		pool.shutdown();
		
		
	}
	
	
	

}
